﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dack_Web2.DTO;
using System.Data.OleDb;

namespace Dack_Web2.DAO
{
    public class SanPhamDAO
    {
        public void Insert(SanPhamDTO tmp)
        {
            string str = "insert into SanPham(MaUser, NgayDang, TenSanPham, ThongTinChiTiet, GiaSanPham, MaLoaiSanPham, HinhGioiThieu) values (@MaUser, @NgayDang, @TenSanPham, @ThongTinChiTiet, @GiaSanPham, @MaLoaiSanPham, @HinhGioiThieu)";
            OleDbParameter[] para1 = {new OleDbParameter("@MaUser", tmp.MaUser),
                                      new OleDbParameter("@NgayDang", tmp.NgayDang),
                                      new OleDbParameter("@TenSanPham", tmp.TenSanPham),
                                      new OleDbParameter("@ThongTinChiTiet", tmp.ThongTinChiTiet),
                                      new OleDbParameter("@GiaSanPham", tmp.GiaSanPham),
                                      new OleDbParameter("@MaLoaiSanPham", tmp.MaLoaiSanPham),
                                      new OleDbParameter("@HinhGioiThieu", tmp.HinhGioiThieu)};

            Sql_DataProvider.SQL_ExecuteNonQuery(str, para1);
        }

        public void Update(SanPhamDTO tmp)
        {
            
            string str = "update SanPham set MaUser=@MaUser, NgayDang=@NgayDang, TenSanPham=@TenSanPham, ThongTinChiTiet=@ThongTinChiTiet, GiaSanPham=@GiaSanPham, MaLoaiSanPham=@MaLoaiSanPham, HinhGioiThieu=@HinhGioiThieu where MaSanPham=@MaSanPham";
      
            OleDbParameter[] para1 = {new OleDbParameter("@MaUser", tmp.MaUser),
                                      new OleDbParameter("@NgayDang", tmp.NgayDang),
                                      new OleDbParameter("@TenSanPham", tmp.TenSanPham),
                                      new OleDbParameter("@ThongTinChiTiet", tmp.ThongTinChiTiet),
                                      new OleDbParameter("@GiaSanPham", tmp.GiaSanPham),
                                      new OleDbParameter("@MaLoaiSanPham", tmp.MaLoaiSanPham),
                                      new OleDbParameter("@HinhGioiThieu", tmp.HinhGioiThieu),
                                      new OleDbParameter("@MaSanPham", tmp.MaSanPham)};
            Sql_DataProvider.SQL_ExecuteNonQuery(str, para1);
        }

        public void Delete(SanPhamDTO tmp)
        {
            OleDbConnection cn = Sql_DataProvider.SQLConnect();
            string str = "delete from SanPham where MaSanPham=@MaSanPham";
            OleDbCommand cmd = new OleDbCommand(str, cn);

            OleDbParameter para1 = new OleDbParameter("@MaSanPham", tmp.MaSanPham);

            cmd.Parameters.Add(para1);

            cmd.ExecuteNonQuery();

            cn.Close();
        }
    }
}